using Godot;
using System;

using CurrentGame.Utils.Interpolation;

namespace CurrentGame.Placements;


public partial class DamageLight : Node2D
{
	[Export]
	public bool ShowLight
	{
		get => _showLight;
		set
		{
			_showLight = value;
			SetLightStatus(value);
		}
	}
	private bool _showLight = true;
	[Export]
	public bool HideLightOnly { get; set; }
	
	[Export]
	public LightPlayerDetect PlayerDetect { get; set; }

	private LerpInterpolation _interpolation;
	private Light2D _light;

	public DamageLight()
	{
		_interpolation = new LerpInterpolation(0.016f, new Vector3(0.001f, -1f, -1f))
		{
			Weight = 0.1f,
			Value = 8.0f
		};
		_interpolation.Teleport();
	}

    public override void _Ready()
    {
		_light = GetNode<Light2D>("PointLight2D");
		SetLightStatus(_showLight);
        if (HideLightOnly) _light.Visible = false;
    }

	// Called every frame. 'delta' is the elapsed time since the previous frame.
	public override void _Process(double delta)
	{
		if (!HideLightOnly && _interpolation.Process(delta))
		{
			_light.Energy = _interpolation.Value;
		}
	}

	private void SetLightStatus(bool show)
	{
		_interpolation.Value = show ? 8.0f : 0.0f;
		PlayerDetect.Monitoring = show;
	}
}
